package com.rice.study.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseDto<T> implements Serializable {
    private Integer code;

    private String msg;

    private T data;

    public ResponseDto(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseDto<T> isSuccessResponse(T data){
        return new ResponseDto<T>(ReturnCode.SUCCESS.getCode(), ReturnCode.SUCCESS.getMsg(), data);
    }

    public static <T> ResponseDto<T> isFailResponse(){
        return isFailResponse(ReturnCode.FAIL.getCode(), ReturnCode.FAIL.getMsg());
    }

    public static <T> ResponseDto<T> isFailResponse(String msg){
        return isFailResponse(ReturnCode.FAIL.getCode(), msg);
    }

    public static <T> ResponseDto<T> isFailResponse(Integer code, String msg){
        return new ResponseDto<T>(code, msg, null);
    }
}
